<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8"/>
    <title>修改密码</title>

    <!-- CSS -->
    <link rel="stylesheet" href="../static/plugins/layui/css/layui.css" th:href="@{static/plugins/layui/css/layui.css}"/>
    <link rel="stylesheet" href="../static/mycss/common.css" th:href="@{static/mycss/common.css}"/>

</head>
<body>
<div>
    <div style="margin: 30px">
        <form class="layui-form">
            <input type="hidden" name="uuid" id="uuid"/>
            <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">* </span>旧密码</label>
                    <div class="layui-input-block">
                        <input type="password" class="layui-input" name="oldPassword" id="oldPassword" lay-verify="required"/>
                    </div>
            </div>
            <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">* </span>新密码</label>
                    <div class="layui-input-block">
                        <input type="password" class="layui-input" name="newPassword" id="newPassword" lay-verify="required"/>
                    </div>
            </div>
            <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color: red">* </span>确认密码</label>
                    <div class="layui-input-block">
                        <input type="password" class="layui-input" name="RenewPassword" id="RenewPassword" lay-verify="required"/>
                    </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                        <button class="layui-btn" lay-submit="" lay-filter="doModFilter">确认修改</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <div class="layui-form-mid layui-word-aux"> <span style="color: red"> （注：修改前先看看跟前有人没）</span></div>
                </div>
            </div>
        </form>
    </div>
</div>

<!-- JS -->
<script type="text/javascript" src="../static/plugins/layui/layui.js" th:src="@{static/plugins/layui/layui.js}"></script>

<script>
    /**
     * 从 sessionStorage 中获取登录人信息
     */
    var userInfo = sessionStorage.getItem("userInfo");

    layui.use(['form', 'layer'], function () {
        var $ = layui.$;
        var form = layui.form;
        var layer = layui.layer;

        /**
         * 表单提交 监听
         */
        form.on('submit(doModFilter)', function (data) {
            var subInfo;//提交信息
            if($("#newPassword").val() != $("#RenewPassword").val()){
                layer.msg('两次密码输入不一致，请重新输入',{icon:5,time:1000});
                $('#newPassword').focus();
                return false;
            }else {
                //提交
                $.ajax({
                    url: 'sysUser/modPassword',
                    type: 'post',
                    data: {jsonStr: JSON.stringify(data.field)},
                    dataType: 'json',//服务器返回的数据类型。
                    success: function (data) {
                        if(0 === data.code){
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.msg(data.msg,{icon:6,time: 1500});
                            parent.layer.close(index);
                        }else{
                            layer.msg(data.msg, {icon: 5, time: 1500});
                        }
                    },
                    error: function (e) {
                    }
                });
            }
            //注：此处必须有这个，因为这里我用了自己的ajax来提交表单，如果不return false，form监听程序本身也会触发提交，可能会出现莫名奇妙的错误
            return false;
        });

    });
</script>

</body>
</html>